#ifndef VIDEOGRAPHICVIEW_H
#define VIDEOGRAPHICVIEW_H

#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPixmap>
#include <QVBoxLayout>
#include <QEvent>
#include <QMoveEvent>
#include <QWindow>

#include "renderinterface.h"

//==============================================================================
//
//==============================================================================
class QLabelWindow : public QWidget
{
    Q_OBJECT
public:
    QLabelWindow(QWidget* parent = nullptr);

    void UpdateLabelText(const std::string& text);

    void UpdatePosition(const QPoint& point);

private:
    QLabel* m_label = nullptr;
};

//==============================================================================
//
//==============================================================================
class ParentEventFilter : public QObject
{
    Q_OBJECT
public:
    ParentEventFilter(QLabelWindow* labelWindow, QWidget* parent);

protected:
    bool eventFilter(QObject* obj, QEvent* event) override;

private:
    QWidget* m_graphics_view = nullptr;
    QLabelWindow* m_labelWindow = nullptr;
};

//==============================================================================
//
//==============================================================================
class GraphicsView : public QGraphicsView, public IRenderView
{
    Q_OBJECT
public:
    GraphicsView(const std::string& render_id,
                 IRenderHandler* handler,
                 QWidget* parent = nullptr);
    ~GraphicsView();

    void paintEvent(QPaintEvent* event) override;

    // IRenderView
    void UpdateLabelText(const std::string& text) override;
    void SetGeometry(int ax, int ay, int aw, int ah) override;
    void* WinId() override;
    void Show() override;

private:
    void UpdateLabelWindowPosition();

private:
    QGraphicsScene* m_scene = nullptr;
    QLabelWindow* m_labelWindow = nullptr;
    IRenderHandler* m_handler = nullptr;
    std::string m_render_id;
};

//==============================================================================
//
//==============================================================================
class WidgetView : public QWidget, public IRenderView
{
    Q_OBJECT
public:
    WidgetView(const std::string& render_id,
               IRenderHandler* handler,
               QWidget* parent = nullptr);

    // IRenderView
    void UpdateLabelText(const std::string& text) override;
    void SetGeometry(int ax, int ay, int aw, int ah) override;
    void* WinId() override;
    void Show() override;

    void paintEvent(QPaintEvent* event) override;
    void resizeEvent(QResizeEvent *event) override;
    void moveEvent(QMoveEvent *event) override;
    bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;

private:
    IRenderHandler* m_handler = nullptr;
    std::string m_render_id;
};


#endif // VIDEOGRAPHICVIEW_H
